/*
 * @Descripttion:
 * @version:
 * @Author: ChenXiang
 * @Date: 2021-03-22 16:18:10
 * @LastEditors: ChenXiang
 * @LastEditTime: 2021-05-26 16:36:32
 */
// 是否为手机号码
export default {
  isMobile: (mobile) => {
    // const regexp = /^1\d{10}$/;//之前的正则
    const regexp = /^0?1[3|4|5|6|7|8|9][0-9]\d{8}$/; // 2020-02-25正则修改了
    if (mobile !== "" && !regexp.test(mobile)) {
      return false;
    } else {
      return true;
    }
  },

  /**
   * 校验联系号码
   * @param {*} 联系号码
   */
  checkPhoneNum: (phoneNum) =>
    /^((1[0-9]{10})|(((([0-9]{3}-)?[0-9]{8})|(([0-9]{4}-)?[0-9]{7}))(-[0-9]{1,4})?))$/.test(
      phoneNum
    ),

  // 15105165020 => 151****5020
  desensitizationPhone: (str) => {
    if (!str) {
      return "";
    }
    const len = str.length;
    const firstStr = str.substr(0, 3);
    const lastStr = str.substr(7);
    const middleStr = str
      .substring(3, len - Math.abs(7))
      .replace(/[\s\S]/gi, "****");
    return firstStr + middleStr + lastStr;
  },

  // 手机号个格式化 166 6666 6666
  mobileFormat: (value) => {
    if (!value) return "";
    const reg = /^(\d{3})(\d{4})(\d{4})$/;
    return value.replace(reg, "$1 $2 $3");
  },

  // 隐藏号码
  filterPhone: (phone) => phone.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2")
};
